(ns example.terminal
  (:require [packet.core :as p]
            [packet.utils :refer [in? hex-string->bytes]]
            [packet.types :refer [deftype u ubcd ud s datetime ipaddr]]
            [example.dlt645 :refer [dlt645]]))


;;提取数据标识的片段
(defn di0 [di] (bit-and di 0xff))
(defn di1 [di] (bit-and (bit-shift-right di 8) 0xff))
(defn di2 [di] (bit-and (bit-shift-right di 16) 0xff))
(defn di3 [di] (bit-and (bit-shift-right di 24) 0xff))
(defn di10 [di] (bit-and di 0xffff))
(defn di32 [di] (bit-and (bit-shift-right di 16) 0xffff))

(deftype voltage (ud 2 0.1))
(deftype current (ud 3 0.001))
(deftype power (ud 3 0.0001))
(deftype energy (ud 4 0.01))
(deftype frequency (ud 2 0.01))
(deftype factor (ud 2 0.001))

(deftype baud "波特率" (u 1 with * 300))

(defn da->point
  "一个da可表示多个测量点，这里假定只有一个"
  [v]
  (let [l (bit-and v 0xff) h (quot v 256)]
    (cond (= l 0xff) 0xffff
          (= l 0) 0
          :else
          (let [n (some #(when (bit-test l %) %) (range 8))]
            (+ (* (dec h) 8) n 1)))))

(defn point->da
  [v]
  (if (or (= v 0) (= v 0xffff))
    v
    (let [h (inc (quot (dec v) 8))
          l (bit-set 0 (rem (dec v) 8))]
      (+ (* h 256) l))))

(deftype point "测量点号" (u 2 with da->point and point->da))

(deftype com-params
    (u 8 as com-addr "通信地址")
  (u 1 as com-type "通道类型" with {2 "GPRS/CDMA" 3 "PSTN" 4 "Ethernet" 6 "RS232/485" 7 "CSD" 8 "Radio"}))

(deftype data
    (cond
      (<= 0xe0000200 $di 0xe0000220)
      [(datetime "mhDMY" as base-time "抄表通道抄表基准时间")
       (u 1 as period-unit "定时抄表周期单位" with ["分" "时" "日" "月"])
       (u 1 as period "定时抄表周期")]

      (<= 0xe0000230 $di 0xe0000250)
      [(u 1 as valid "有效性标志" with ["无效" "有效"])
       (ubcd 2 as point-count "存储点数")
       (u 1 as meter-type "电表类型" with {1 "单相电子表" 2 "多功能表" 3 "其他类型" 255 "所有类型"})
       (u 1 as user-type "重点用户属性" with {0 "普通用户" 1 "重点用户" 255 "所有类型"})
       (u 1 count-of das)
       (repeat as das (point "信息点标识"))
       (u 1 count-of dis)
       (repeat as dis (u 4 "数据标识"))]

      (<= 0xe0000301 $di 0xe00003fe)
      [(u 1 as valid "有效性标志")
       (datetime "mhDMY" as report-base-time "上报基准时间")
       (u 1 as report-period-unit "定时上报周期单位" with ["分" "时" "日" "月"])
       (u 1 as report-period "定时上报周期")
       (u 1 as data-mode "数据结构方式")
       (datetime "mhDMY" as measure-base-time "采样基准时间")
       (u 1 as measure-period-unit "定时采样周期单位" with ["分" "时" "日" "月"])
       (u 1 as measure-period "定时采样周期")
       (u 1 as multiplying "数据抽取倍率")
       (u 2 as times "执行次数")
       (u 1 "信息点标识组数" count-of das)
       (repeat as das "信息点标识数组" (point))
       (u 1 "数据标识编码组数" count-of dis)
       (repeat as dis "数据标识数组" (u 4))]

      (<= 0xe0000401 $di 0xe00004fe) ;中继任务参数表
      [(u 1 as valid "有效性标志")
       (datetime "mhDMY" as report-base-time "上报基准时间")
       (u 1 as report-period-unit "定时上报周期单位" with ["分" "时" "日" "月"])
       (u 1 as report-period "定时上报周期")
       (datetime "mhDMY" as measure-base-time "采样基准时间")
       (u 1 as measure-period-unit "定时采样周期单位" with ["分" "时" "日" "月"])
       (u 1 as measure-period "定时采样周期")
       (u 1 as multiplying "数据抽取倍率")
       (u 1 as relay-mode "中继类型")
       (u 2 as times "执行次数")
       (u 1 as port "端口号")
       (baud as baudrate)
       (u 1 as check-mode with ["无校验" "偶校验" "奇校验"])
       (ubcd 1 as data-bits "数据位")
       (u 1 as stop-bits "停止位" with ["1位" "1.5位" "2位"])
       (ubcd 1 as time-out "超时时间(秒)")
       (u 1 length-of dlt645)
       (packet dlt645 "中继报文")]

      (and (= (di3 $di) 0) (<= (di1 $di) 0x3f) (= (di0 $di) 0))
      (energy as e)

      (<= 0x0201 (di32 $di) 0x0204)
      (case (di32 $di)
        0x0201 (voltage as u)
        0x0202 (current as i)
        0x0203 (power as p)
        0x0204 (power as q))

      :else
      (case $di
        0xe0000000 (u 1 as confirm "确认" with ["全部肯定" "全部否定"])
        
        0xe0000100 (com-params as com0 "主站通信参数")
        0xe0000101 (com-params as com1 "备用主站1通信参数")
        0xe0000102 (com-params as com2 "备用主站2通信参数")
        0xe0000103 (u 8 as proxy-server "网关或代理服务器地址")
        0xe0000104 (s 16 as apn "APN")
        0xe0000105 (s 32 as user-name "登录用户名")
        0xe0000106 (s 32 as password "登录口令")
        0xe0000107 (ubcd 1 as heart-beat "心跳周期(分)")
        0xe0000108 (ubcd 1 as redial "掉线重拨间隔(分)")
        0xe0000109 (ubcd 1 as times "掉线重拨次数")
        0xe000010a (u 1 as tm "传输层方式" with ["TCP" "UDP"])
        0xe000010b (u 1 as enc "编码压缩方式" with ["非压缩" "压缩BIN编码"])
        0xe000010f (++ 0xe0000100 - 0xe000010b)

        0xe0000110 (u 1 as net-mode "终端通信网络模式" with {1 "2G" 2 "3G" 4 "4G"})

        0xe0000120 (ubcd 3 as zone-addr "地区码")
        0xe0000121 (u 3 as terminal-addr "终端地址")
        0xe0000122 (u 1 as mode "终端通信工作方式" with ["混合模式" "客户机模式" "服务器模式"])
        0xe0000123 (u 2 as port "监听端口号")
        0xe0000124 (ipaddr as ip "终端当前通道IP地址")
        0xe0000125 (u 4 as mask "终端当前通道子网掩码")
        0xe0000126 (ipaddr as gateway "终端当前通道网关地址")
        0xe0000127 (u 1 as fetch-mode "有线网络IP地址获取方式")
        0xe000012f (++ 0xe0000120 - 0xe000012f)
        
        0xe0000130 (datetime "smhDMY" as terminal-time "终端时间")
        0xe0000221 (ubcd 1 as config-count "有效的抄表参数配置表总数")
        0xe0000300 (ubcd 1 as task-count "有效的普通任务总数")
        0xe0000400 (ubcd 1 as relay-count "有效的中继任务总数")

        0xe0800000 (u 1 as valid "测量点状态" with ["无效" "有效"])
        0xe0800001 (u 1 as point-type "测量点性质" with ["?" "485表" "模拟量" "脉冲量" "计算值" "交流采样"])
        0xe0800002 (ubcd 6 as ma "测量点地址")
        0xe0800003 (u 1 as protocol "测量点通信规约" with ["DL/T645-1997规约" "DL/T645-2007规约" "广东97电表规约" "广东07电表规约" "威胜自定义规约"])
        0xe0800004 (u 1 as meter-type "电量表类型" with ["?" "单相电子表" "多功能表" "其它类型"])
        0xe0800005 (u 1 as coll "总分类型" with ["用户表" "总表"])
        0xe0800006 (u 1 as vip "重点用户属性" with ["普通用户" "重点用户"])
        0xe0800007 (u 1 as cutoff "拉闸功能" with ["不带拉闸" "带拉闸"])
        0xe0800008 (ubcd 1 as fees "最大费率数")
        0xe0800009 (u 6 as ga "测量点对应采集器地址")
        0xe080000a (u 1 as port "测量点端口号")
        0xe080000b [(baud as baudrate)
                    (u 1 as check-mode with ["无校验" "偶校验" "奇校验"])
                    (u 1 as datalen "数据位")
                    (u 1 as stop-bits with ["1位" "1.5位" "2位"])]
        0xe080000c (ubcd 2 as ta "TA变比")
        0xe080000d (ubcd 2 as tv "TV变比")
        0xe080000f (++ 0xe0800000 - 0xe080000d)

        0xe0800030 (flag
                    (b0-2 as phase "相别" with {1 "A相" 2 "B相" 4 "C相" 7 "三相"})
                    (b3-4 as phase-cap "相线特征" with ["支持相线识别"
                                                        "不支持相线识别"
                                                        "相线不确定"
                                                        "保留"]))
        
        0xe1800005 (ubcd 2 as da-count "有效的测量点总数")
        0xe1800009 [(ubcd 2 "要抄电表总块数")
                    (ubcd 2 "抄表成功块数")
                    (datetime "smhDMY" "抄表开始时间")
                    (datetime "smhDMY" "抄表结束时间")]
        
        0x0000ff00 [(ubcd 1 "费率数" count-of es)
                    (repeat as es (energy))])))

(p/defpacket terminal :little-endian
  (skip-until 0x68
              (u 2 as cad-len "数据长度")
              (u 2 should = $cad-len)
              0x68)
  (label beginning)
  (flag
   (b7 as dir "传输方向位" with [:down :up])
   (b6 as prm "启动标志位" with [:from-slave :from-master])
   (if (= $dir :down)
     [(b5 as fcb "帧计数位")
      (b4 as fcv "帧计数有效位" with [:invalid :valid])]
     (b5 as acd "请求访问位" with [:no-data :has-data]))
   (if (= $prm :from-master) 
     (b0-3 as fc "功能码" with {1 :reset 4 :user-data 8 :reserve 9 :link-test 10 :req-level-1 11 :req-level-2})
     (b0-3 as fc "功能码" with {0 :confirm 8 :user-data 9 :no-data 10 :reserve 11 :link-status})))

  (ubcd 3 as a1 "地区码")
  (u 3 as a2 "终端地址")
  (u 1 as a3 "主站地址")
  (u 1 as afc "应用层功能码"
     with {0 :confirm 1 :reset 2 :link-test
           4 :write-parameter 6 :security 
           10 :read-parameter 
           12 :read-data 13 :read-history 14 :read-event 15 :file-transfer
           16 :relay 18 :read-task 19 :read-alarm
           20 :cascade-cmd 21 :user-defined-data})

  (flag
   (b7 as tpv "带时标" with [:no-timestamp :with-timestamp])
   (b5-6 as frame-type "连续帧类型" with [:middle :last :first :single])
   (b4 as con "要求确认" with [:no :yes])
   (b0-3 as frame-seq "帧序号"))

  (attempt-repeat #_while as body
         #_(< (+ $=
               (if (or (= $afc :security) (and (= $dir :down) (= $afc :write-parameter))) 16 0)
               (if (= $tpv :with-timestamp) 5 0))
            (+ $cad-len 6))
         (point as da "信息点标识")
         (u 4 as di "数据标识")
         (cond
           (= $afc :confirm)
           (u 1 as confirm "确认" with ["确定" "否定"])
           
           (and (= $afc :write-parameter) (= $dir :up))
           (u 1 as ecode "错误码" with ["正确" "中继命令没有返回" "设置内容非法" "密码权限不足"
                                        "无此数据项" "命令时间失效" "目标地址不存在" "校验失败"])

           (and (= $dir :down) (in? $afc :read-history :read-event :read-task :read-alarm))
           [(datetime "YYMDhm" as start-time "起始时间")
            (datetime "YYMDhm" as end-time "结束时间")
            (when (in? $afc :read-history :read-task)
              (u 1 as ddens "数据密度" with [:by-terminal :one-minute :five-minute :fifteen-minute
                                             :half-an-hour :one-hour :one-day :one-month :payday]))]
           
           (and (= $dir :up) (in? $afc :read-history :read-task))
           (while as data (< (+ $=
                                (if (or (= $afc :security) (and (= $dir :down) (= $afc :write-parameter))) 16 0)
                                (if (= $tpv :with-timestamp) 5 0))
                             (+ $cad-len 6))
                  (data)
                  (datetime "YYMDhm" as start-time "起始时间")) 

           (= $afc :relay) ;中继报文
           [(ubcd 1 as relay-type "中继类型"
                  with {0 "普通中继" 1 "拉闸命令" 2 "允许合闸命令" 3 "保电投入" 4 "保电解除"})
            (when (= $dir :down)
              (u 1 as port "端口号")
              (baud as baudrate "波特率")
              (u 1 as cs "校验方式")
              (ubcd 1 as bit-len "数据位")
              (u 1 as stop "停止位")
              (ubcd 1 as timeout "超时时间(秒)"))
            (u 1 length-of dlt645)
            (packet dlt645 "中继报文")]
           
           (= $dir :up)
           (data)

           :else
           (succeed)))
  
  (when (or (= $afc :security) (and (= $dir :down) (= $afc :write-parameter)))
    (s 16 as pw "消息认证码"))
  (when (= $tpv :with-timestamp)
    (datetime "smhD" as send_time "启动帧发送时标")
    (u 1 as allowed_delay "允许发送传输延时时间"))
  (u 1 "校验和" checksum from beginning use packet.checksum/cs8)
  0x16)

(def packets
  (mapv #(byte-array (hex-string->bytes %))
        ["68 1F 00 1F 00 68 88 60 09 44 42 43 01 00 10 61 02 01 01 00 02 E3 00 0D 68 95 40 06 00 17 10 68 D1 01 34 D8 16 E8 16"
         "68 89 00 89 00 68 88 60 09 44 42 43 01 00 10 6C 04 04 01 00 02 E3 00 77 68 76 33 00 00 80 33 68 B1 6B 33 33 33 39 D3 D3 95 63 3C 4C 35 4B 9C 55 A6 56 66 56 33 33 33 33 33 33 33 33 33 C9 7C DD 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 DD 33 43 33 43 33 43 33 43 DD 36 CB 34 33 33 33 33 33 98 58 34 33 B8 33 33 33 DD 54 58 34 33 B8 33 33 33 33 33 33 33 77 33 33 33 DD 34 33 33 33 33 33 DD 90 18 3E 16 2E 16"
         "68 29 00 29 00 68 4B 60 09 44 42 43 01 00 10 61 02 01 01 00 02 E3 00 1F 08 01 08 00 30 11 68 95 40 06 00 17 10 68 11 05 33 33 33 39 C9 83 16 65 16"
         "68 11 00 11 00 68 88 60 09 44 42 43 01 00 0A 60 02 01 30 00 80 E0 04 BC 16"
         "68 2D 00 2D 00 68 88 60 09 44 42 43 01 00 0A 6F 02 01 0F 00 80 E0 01 01 95 40 06 00 17 10 01 02 00 00 01 04 FF FF FF FF FF FF 1F 08 01 08 00 01 00 01 00 DE 16"
         "68 2D 00 2D 00 68 88 60 09 44 42 43 01 00 0A 6E 01 01 0F 00 80 E0 00 01 01 00 00 00 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 04 01 08 00 01 00 01 00 BA 16"
         "68 12 00 12 00 68 88 60 09 44 42 43 01 00 0C 6D 00 00 05 00 80 E1 50 00 EA 16"
         "68 10 00 10 00 68 4B 60 09 44 42 43 01 00 0C 6D 00 00 05 00 80 E1 5D 16"
         "68 70 03 70 03 68 C8 10 09 44 15 69 00 00 0D 66 00 00 00 00 03 02 FF FF FF 20 21 06 25 00 00 FF FF FF 20 21 06 25 00 15 FF FF FF 20 21 06 25 00 30 FF FF FF 20 21 06 25 00 45 FF FF FF 20 21 06 25 01 00 FF FF FF 20 21 06 25 01 15 FF FF FF 20 21 06 25 01 30 FF FF FF 20 21 06 25 01 45 FF FF FF 20 21 06 25 02 00 FF FF FF 20 21 06 25 02 15 FF FF FF 20 21 06 25 02 30 FF FF FF 20 21 06 25 02 45 FF FF FF 20 21 06 25 03 00 FF FF FF 20 21 06 25 03 15 FF FF FF 20 21 06 25 03 30 FF FF FF 20 21 06 25 03 45 FF FF FF 20 21 06 25 04 00 FF FF FF 20 21 06 25 04 15 FF FF FF 20 21 06 25 04 30 FF FF FF 20 21 06 25 04 45 FF FF FF 20 21 06 25 05 00 FF FF FF 20 21 06 25 05 15 FF FF FF 20 21 06 25 05 30 FF FF FF 20 21 06 25 05 45 FF FF FF 20 21 06 25 06 00 FF FF FF 20 21 06 25 06 15 FF FF FF 20 21 06 25 06 30 FF FF FF 20 21 06 25 06 45 FF FF FF 20 21 06 25 07 00 FF FF FF 20 21 06 25 07 15 FF FF FF 20 21 06 25 07 30 FF FF FF 20 21 06 25 07 45 FF FF FF 20 21 06 25 08 00 FF FF FF 20 21 06 25 08 15 FF FF FF 20 21 06 25 08 30 FF FF FF 20 21 06 25 08 45 FF FF FF 20 21 06 25 09 00 FF FF FF 20 21 06 25 09 15 FF FF FF 20 21 06 25 09 30 FF FF FF 20 21 06 25 09 45 FF FF FF 20 21 06 25 10 00 FF FF FF 20 21 06 25 10 15 FF FF FF 20 21 06 25 10 30 FF FF FF 20 21 06 25 10 45 FF FF FF 20 21 06 25 11 00 FF FF FF 20 21 06 25 11 15 FF FF FF 20 21 06 25 11 30 FF FF FF 20 21 06 25 11 45 FF FF FF 20 21 06 25 12 00 FF FF FF 20 21 06 25 12 15 FF FF FF 20 21 06 25 12 30 FF FF FF 20 21 06 25 12 45 FF FF FF 20 21 06 25 13 00 FF FF FF 20 21 06 25 13 15 FF FF FF 20 21 06 25 13 30 FF FF FF 20 21 06 25 13 45 FF FF FF 20 21 06 25 14 00 FF FF FF 20 21 06 25 14 15 FF FF FF 20 21 06 25 14 30 FF FF FF 20 21 06 25 14 45 FF FF FF 20 21 06 25 15 00 FF FF FF 20 21 06 25 15 15 FF FF FF 20 21 06 25 15 30 FF FF FF 20 21 06 25 15 45 FF FF FF 20 21 06 25 16 00 59 04 00 20 21 06 25 16 15 58 04 00 20 21 06 25 16 30 58 04 00 20 21 06 25 16 45 55 04 00 20 21 06 25 17 00 FF FF FF 20 21 06 25 17 15 FF FF FF 20 21 06 25 17 30 FF FF FF 20 21 06 25 17 45 FF FF FF 20 21 06 25 18 00 FF FF FF 20 21 06 25 18 15 FF FF FF 20 21 06 25 18 30 FF FF FF 20 21 06 25 18 45 FF FF FF 20 21 06 25 19 00 FF FF FF 20 21 06 25 19 15 FF FF FF 20 21 06 25 19 30 FF FF FF 20 21 06 25 19 45 FF FF FF 20 21 06 25 20 00 FF FF FF 20 21 06 25 20 15 FF FF FF 20 21 06 25 20 30 FF FF FF 20 21 06 25 20 45 FF FF FF 20 21 06 25 21 00 FF FF FF 20 21 06 25 21 15 FF FF FF 20 21 06 25 21 30 FF FF FF 20 21 06 25 21 45 FF FF FF 20 21 06 25 22 00 FF FF FF 20 21 06 25 22 15 FF FF FF 20 21 06 25 22 30 FF FF FF 20 21 06 25 22 45 FF FF FF 20 21 06 25 23 00 FF FF FF 20 21 06 25 23 15 FF FF FF 20 21 06 25 23 30 FF FF FF 20 21 06 25 23 45 E5 16"
         "68 10 03 10 03 68 C8 10 09 44 15 69 00 00 0D 60 00 00 00 01 01 02 FF FF 20 21 06 25 00 00 FF FF 20 21 06 25 00 15 FF FF 20 21 06 25 00 30 FF FF 20 21 06 25 00 45 FF FF 20 21 06 25 01 00 FF FF 20 21 06 25 01 15 FF FF 20 21 06 25 01 30 FF FF 20 21 06 25 01 45 FF FF 20 21 06 25 02 00 FF FF 20 21 06 25 02 15 FF FF 20 21 06 25 02 30 FF FF 20 21 06 25 02 45 FF FF 20 21 06 25 03 00 FF FF 20 21 06 25 03 15 FF FF 20 21 06 25 03 30 FF FF 20 21 06 25 03 45 FF FF 20 21 06 25 04 00 FF FF 20 21 06 25 04 15 FF FF 20 21 06 25 04 30 FF FF 20 21 06 25 04 45 FF FF 20 21 06 25 05 00 FF FF 20 21 06 25 05 15 FF FF 20 21 06 25 05 30 FF FF 20 21 06 25 05 45 FF FF 20 21 06 25 06 00 FF FF 20 21 06 25 06 15 FF FF 20 21 06 25 06 30 FF FF 20 21 06 25 06 45 FF FF 20 21 06 25 07 00 FF FF 20 21 06 25 07 15 FF FF 20 21 06 25 07 30 FF FF 20 21 06 25 07 45 FF FF 20 21 06 25 08 00 FF FF 20 21 06 25 08 15 FF FF 20 21 06 25 08 30 FF FF 20 21 06 25 08 45 FF FF 20 21 06 25 09 00 FF FF 20 21 06 25 09 15 FF FF 20 21 06 25 09 30 FF FF 20 21 06 25 09 45 FF FF 20 21 06 25 10 00 FF FF 20 21 06 25 10 15 FF FF 20 21 06 25 10 30 FF FF 20 21 06 25 10 45 FF FF 20 21 06 25 11 00 FF FF 20 21 06 25 11 15 FF FF 20 21 06 25 11 30 FF FF 20 21 06 25 11 45 FF FF 20 21 06 25 12 00 FF FF 20 21 06 25 12 15 FF FF 20 21 06 25 12 30 FF FF 20 21 06 25 12 45 FF FF 20 21 06 25 13 00 FF FF 20 21 06 25 13 15 FF FF 20 21 06 25 13 30 FF FF 20 21 06 25 13 45 FF FF 20 21 06 25 14 00 FF FF 20 21 06 25 14 15 FF FF 20 21 06 25 14 30 FF FF 20 21 06 25 14 45 FF FF 20 21 06 25 15 00 FF FF 20 21 06 25 15 15 FF FF 20 21 06 25 15 30 FF FF 20 21 06 25 15 45 FF FF 20 21 06 25 16 00 29 23 20 21 06 25 16 15 23 23 20 21 06 25 16 30 24 23 20 21 06 25 16 45 15 23 20 21 06 25 17 00 FF FF 20 21 06 25 17 15 FF FF 20 21 06 25 17 30 FF FF 20 21 06 25 17 45 FF FF 20 21 06 25 18 00 FF FF 20 21 06 25 18 15 FF FF 20 21 06 25 18 30 FF FF 20 21 06 25 18 45 FF FF 20 21 06 25 19 00 FF FF 20 21 06 25 19 15 FF FF 20 21 06 25 19 30 FF FF 20 21 06 25 19 45 FF FF 20 21 06 25 20 00 FF FF 20 21 06 25 20 15 FF FF 20 21 06 25 20 30 FF FF 20 21 06 25 20 45 FF FF 20 21 06 25 21 00 FF FF 20 21 06 25 21 15 FF FF 20 21 06 25 21 30 FF FF 20 21 06 25 21 45 FF FF 20 21 06 25 22 00 FF FF 20 21 06 25 22 15 FF FF 20 21 06 25 22 30 FF FF 20 21 06 25 22 45 FF FF 20 21 06 25 23 00 FF FF 20 21 06 25 23 15 FF FF 20 21 06 25 23 30 FF FF 20 21 06 25 23 45 DD 16"
         "68 10 00 10 00 68 4B 17 73 44 B3 23 5B 00 0A 6A 08 01 0F 00 80 E0 36 16"
         "68 1F 00 1F 00 68 8A 17 73 44 B3 23 5B 00 10 69 04 01 01 00 02 E3 00 0D 68 52 52 65 00 17 03 68 D1 01 35 FA 16 04 16"
         "68 29 00 29 00 68 4B 17 73 44 B3 23 5B 00 10 63 01 01 01 00 02 E3 00 1F 08 01 08 00 30 11 68 41 06 01 00 30 13 68 11 05 33 33 33 39 CC 0F 16 4A 16"
         "68 D0 03 D0 03 68 C8 10 09 44 15 69 00 00 0D 67 00 00 00 00 01 00 FF FF FF FF 20 21 06 25 00 00 FF FF FF FF 20 21 06 25 00 15 FF FF FF FF 20 21 06 25 00 30 FF FF FF FF 20 21 06 25 00 45 FF FF FF FF 20 21 06 25 01 00 FF FF FF FF 20 21 06 25 01 15 FF FF FF FF 20 21 06 25 01 30 FF FF FF FF 20 21 06 25 01 45 FF FF FF FF 20 21 06 25 02 00 FF FF FF FF 20 21 06 25 02 15 FF FF FF FF 20 21 06 25 02 30 FF FF FF FF 20 21 06 25 02 45 FF FF FF FF 20 21 06 25 03 00 FF FF FF FF 20 21 06 25 03 15 FF FF FF FF 20 21 06 25 03 30 FF FF FF FF 20 21 06 25 03 45 FF FF FF FF 20 21 06 25 04 00 FF FF FF FF 20 21 06 25 04 15 FF FF FF FF 20 21 06 25 04 30 FF FF FF FF 20 21 06 25 04 45 FF FF FF FF 20 21 06 25 05 00 FF FF FF FF 20 21 06 25 05 15 FF FF FF FF 20 21 06 25 05 30 FF FF FF FF 20 21 06 25 05 45 FF FF FF FF 20 21 06 25 06 00 FF FF FF FF 20 21 06 25 06 15 FF FF FF FF 20 21 06 25 06 30 FF FF FF FF 20 21 06 25 06 45 FF FF FF FF 20 21 06 25 07 00 FF FF FF FF 20 21 06 25 07 15 FF FF FF FF 20 21 06 25 07 30 FF FF FF FF 20 21 06 25 07 45 FF FF FF FF 20 21 06 25 08 00 FF FF FF FF 20 21 06 25 08 15 FF FF FF FF 20 21 06 25 08 30 FF FF FF FF 20 21 06 25 08 45 FF FF FF FF 20 21 06 25 09 00 FF FF FF FF 20 21 06 25 09 15 FF FF FF FF 20 21 06 25 09 30 FF FF FF FF 20 21 06 25 09 45 FF FF FF FF 20 21 06 25 10 00 FF FF FF FF 20 21 06 25 10 15 FF FF FF FF 20 21 06 25 10 30 FF FF FF FF 20 21 06 25 10 45 FF FF FF FF 20 21 06 25 11 00 FF FF FF FF 20 21 06 25 11 15 FF FF FF FF 20 21 06 25 11 30 FF FF FF FF 20 21 06 25 11 45 FF FF FF FF 20 21 06 25 12 00 FF FF FF FF 20 21 06 25 12 15 FF FF FF FF 20 21 06 25 12 30 FF FF FF FF 20 21 06 25 12 45 FF FF FF FF 20 21 06 25 13 00 FF FF FF FF 20 21 06 25 13 15 FF FF FF FF 20 21 06 25 13 30 FF FF FF FF 20 21 06 25 13 45 FF FF FF FF 20 21 06 25 14 00 FF FF FF FF 20 21 06 25 14 15 FF FF FF FF 20 21 06 25 14 30 FF FF FF FF 20 21 06 25 14 45 FF FF FF FF 20 21 06 25 15 00 FF FF FF FF 20 21 06 25 15 15 FF FF FF FF 20 21 06 25 15 30 FF FF FF FF 20 21 06 25 15 45 FF FF FF FF 20 21 06 25 16 00 95 00 00 00 20 21 06 25 16 15 96 00 00 00 20 21 06 25 16 30 97 00 00 00 20 21 06 25 16 45 98 00 00 00 20 21 06 25 17 00 FF FF FF FF 20 21 06 25 17 15 FF FF FF FF 20 21 06 25 17 30 FF FF FF FF 20 21 06 25 17 45 FF FF FF FF 20 21 06 25 18 00 FF FF FF FF 20 21 06 25 18 15 FF FF FF FF 20 21 06 25 18 30 FF FF FF FF 20 21 06 25 18 45 FF FF FF FF 20 21 06 25 19 00 FF FF FF FF 20 21 06 25 19 15 FF FF FF FF 20 21 06 25 19 30 FF FF FF FF 20 21 06 25 19 45 FF FF FF FF 20 21 06 25 20 00 FF FF FF FF 20 21 06 25 20 15 FF FF FF FF 20 21 06 25 20 30 FF FF FF FF 20 21 06 25 20 45 FF FF FF FF 20 21 06 25 21 00 FF FF FF FF 20 21 06 25 21 15 FF FF FF FF 20 21 06 25 21 30 FF FF FF FF 20 21 06 25 21 45 FF FF FF FF 20 21 06 25 22 00 FF FF FF FF 20 21 06 25 22 15 FF FF FF FF 20 21 06 25 22 30 FF FF FF FF 20 21 06 25 22 45 FF FF FF FF 20 21 06 25 23 00 FF FF FF FF 20 21 06 25 23 15 FF FF FF FF 20 21 06 25 23 30 FF FF FF FF 20 21 06 25 23 45 72 16"
         "68 10 03 10 03 68 C8 10 09 44 15 69 00 00 0D 60 00 00 00 01 01 02 FF FF 20 21 06 25 00 00 FF FF 20 21 06 25 00 15 FF FF 20 21 06 25 00 30 FF FF 20 21 06 25 00 45 FF FF 20 21 06 25 01 00 FF FF 20 21 06 25 01 15 FF FF 20 21 06 25 01 30 FF FF 20 21 06 25 01 45 FF FF 20 21 06 25 02 00 FF FF 20 21 06 25 02 15 FF FF 20 21 06 25 02 30 FF FF 20 21 06 25 02 45 FF FF 20 21 06 25 03 00 FF FF 20 21 06 25 03 15 FF FF 20 21 06 25 03 30 FF FF 20 21 06 25 03 45 FF FF 20 21 06 25 04 00 FF FF 20 21 06 25 04 15 FF FF 20 21 06 25 04 30 FF FF 20 21 06 25 04 45 FF FF 20 21 06 25 05 00 FF FF 20 21 06 25 05 15 FF FF 20 21 06 25 05 30 FF FF 20 21 06 25 05 45 FF FF 20 21 06 25 06 00 FF FF 20 21 06 25 06 15 FF FF 20 21 06 25 06 30 FF FF 20 21 06 25 06 45 FF FF 20 21 06 25 07 00 FF FF 20 21 06 25 07 15 FF FF 20 21 06 25 07 30 FF FF 20 21 06 25 07 45 FF FF 20 21 06 25 08 00 FF FF 20 21 06 25 08 15 FF FF 20 21 06 25 08 30 FF FF 20 21 06 25 08 45 FF FF 20 21 06 25 09 00 FF FF 20 21 06 25 09 15 FF FF 20 21 06 25 09 30 FF FF 20 21 06 25 09 45 FF FF 20 21 06 25 10 00 FF FF 20 21 06 25 10 15 FF FF 20 21 06 25 10 30 FF FF 20 21 06 25 10 45 FF FF 20 21 06 25 11 00 FF FF 20 21 06 25 11 15 FF FF 20 21 06 25 11 30 FF FF 20 21 06 25 11 45 FF FF 20 21 06 25 12 00 FF FF 20 21 06 25 12 15 FF FF 20 21 06 25 12 30 FF FF 20 21 06 25 12 45 FF FF 20 21 06 25 13 00 FF FF 20 21 06 25 13 15 FF FF 20 21 06 25 13 30 FF FF 20 21 06 25 13 45 FF FF 20 21 06 25 14 00 FF FF 20 21 06 25 14 15 FF FF 20 21 06 25 14 30 FF FF 20 21 06 25 14 45 FF FF 20 21 06 25 15 00 FF FF 20 21 06 25 15 15 FF FF 20 21 06 25 15 30 FF FF 20 21 06 25 15 45 FF FF 20 21 06 25 16 00 29 23 20 21 06 25 16 15 23 23 20 21 06 25 16 30 24 23 20 21 06 25 16 45 15 23 20 21 06 25 17 00 FF FF 20 21 06 25 17 15 FF FF 20 21 06 25 17 30 FF FF 20 21 06 25 17 45 FF FF 20 21 06 25 18 00 FF FF 20 21 06 25 18 15 FF FF 20 21 06 25 18 30 FF FF 20 21 06 25 18 45 FF FF 20 21 06 25 19 00 FF FF 20 21 06 25 19 15 FF FF 20 21 06 25 19 30 FF FF 20 21 06 25 19 45 FF FF 20 21 06 25 20 00 FF FF 20 21 06 25 20 15 FF FF 20 21 06 25 20 30 FF FF 20 21 06 25 20 45 FF FF 20 21 06 25 21 00 FF FF 20 21 06 25 21 15 FF FF 20 21 06 25 21 30 FF FF 20 21 06 25 21 45 FF FF 20 21 06 25 22 00 FF FF 20 21 06 25 22 15 FF FF 20 21 06 25 22 30 FF FF 20 21 06 25 22 45 FF FF 20 21 06 25 23 00 FF FF 20 21 06 25 23 15 FF FF 20 21 06 25 23 30 FF FF 20 21 06 25 23 45 DD 16 "
         "68 1D 00 1D 00 68 4B 10 09 44 15 69 00 00 0D 60 00 00 00 01 01 02 20 21 06 25 00 00 20 21 06 26 00 00 00 70 16"]))

#_(doseq [p packets] (p/test-packet terminal p))

